package com.bcu.cn.onlineexamsystem.user.controller;

import com.bcu.cn.onlineexamsystem.user.entity.Course;
import com.bcu.cn.onlineexamsystem.user.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    // 管理员课程管理页面
    @GetMapping("/course")
    public String manageCourses(Model model) {
        model.addAttribute("courses", adminService.getAllCourses());
        return "admin/course";
    }

    // 管理员添加课程
    @PostMapping("/course")
    public String addCourse(@RequestParam String courseId,
                            @RequestParam String courseName,
                            @RequestParam String teacherId) {
        Course course = new Course();
        course.setCourseId(courseId);
        course.setCourseName(courseName);
        course.setTeacherId(teacherId);
        adminService.manageCourse(course);
        return "redirect:/admin/course";
    }

    // 管理员删除成绩记录
    @GetMapping("/deleteScore/{id}")
    public String deleteScore(@PathVariable Long id) {
        adminService.deleteScore(id);
        return "redirect:/admin/course";
    }
}
